package jvm.classLoader;


/**
 * 静态变量、静态初始化块，变量、初始化块初始化了顺序取决于它们在类中出现的先后顺序。
 *
 * 1. int counter1 = 1;
 * 2. Singleton singleton = new Singleton(); ===>
 * 赋值前，都是初始值0
 *  counter1 ++;
 *         counter2 ++;
 *
 *  3. int counter2 = 0;
 */
public class MyTest05 {
    public static void main(String[] args) {
        Singleton singleton = Singleton.getInstance();
        System.out.println("counter1--------->" + Singleton.counter1);
        System.out.println("counter2--------->" + Singleton.counter2);

    }
}

class Singleton{
    public static int counter1 = 1;

    private static Singleton singleton = new Singleton();

    private Singleton() {
        counter1 ++;
        counter2 ++;
    }

    public static int counter2 = 0;

    public static Singleton getInstance(){
        return singleton;
    }
}